home *** CD-ROM | disk | FTP | other *** search
- #include <btrvexp.h>
- #include <stdio.h>
-
- main()
- {
- /* Record Buffer for AREACODE.DAT */
- struct
- {
- char state[15];
- char areacode[3];
- char code[2];
- char crlf[2]; /* This is truncated when ADDed */
- } record;
-
-
- int recs,temp;
- FILE *infile;
- STATBUF statbuf;
- char path[80];
-
- BSTART();
- B_OPENMODE = B_ACCELERATED;
-
- statbuf.reclen = 20 ;
- statbuf.pgsize = 512 ;
- statbuf.numind = 3 ;
- statbuf.numrecs = 0L;
- statbuf.fileflags = 0 ;
-
- statbuf.segment[0].key_pos = 1;
- statbuf.segment[0].key_len = 15;
- statbuf.segment[0].key_flags = DUPLICATE | SEGMENTED | ALT_COL_SEQ | EXTENDED;
- statbuf.segment[0].ext_key_type = B_ZSTRING;
-
- statbuf.segment[1].key_pos = 16;
- statbuf.segment[1].key_len = 3;
- statbuf.segment[1].key_flags = DUPLICATE;
-
- statbuf.segment[2].key_pos = 16;
- statbuf.segment[2].key_len = 3;
- statbuf.segment[2].key_flags = 0;
-
- statbuf.segment[3].key_pos = 19;
- statbuf.segment[3].key_len = 2;
- statbuf.segment[3].key_flags = DUPLICATE | ALT_COL_SEQ;
-
- _searchenv("UPPER.ALT","PATH",path);
- if (path[0] != '\0')
- {
- infile = fopen(path,"rb");
- if ( fread(&statbuf.segment[4],265,1,infile) == 0)
- {
- printf("Could not read UPPER.ALT");
- exit(0);
- }
- fclose(infile);
- }
- else
- {
- printf("Could not find UPPER.ALT\n");
- exit(0);
- }
-
- statbuf.buf_len = 345; /* (1 * 16 byte header)
- + (4 * 16 byte segments)
- + ( 265 byte alternate collating sequence) */
-
- BCREATE("areacode.dat",&statbuf);
- infile = fopen("areacode.txt","rb");
- while ( fread(record.state,22,1,infile) != NULL)
- {
- BADD("areacode.dat",&record);
- if (BSTATUS != 0)
- {
- GET_ERR_MSG(BSTATUS);
- printf("Btrieve Error %d on \"%.18s\"\n%s\n\n",errmsg.errnum,&record,errmsg.descrip);
- }
- }
- fclose(infile);
-
- BFILEINFO("areacode.dat",NUM_RECS,&recs);
- printf("\n\nThere are %d records in the file\n\n",recs);
-
- BCLOSE(ALL_FILES);
-
- }
-